var express = require('express');
// Date.prototype.toJSON = function () {
//   var timezoneOffsetInHours = -(this.getTimezoneOffset() / 60); //UTC minus local time
//   var sign = timezoneOffsetInHours >= 0 ? '+' : '-';
//   var leadingZero = (Math.abs(timezoneOffsetInHours) < 10) ? '0' : '';
//
//   //It's a bit unfortunate that we need to construct a new Date instance
//   //(we don't want _this_ Date instance to be modified)
//   var correctedDate = new Date(this.getFullYear(), this.getMonth(),
//       this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds(),
//       this.getMilliseconds());
//   correctedDate.setHours(this.getHours() + timezoneOffsetInHours);
//   var iso = correctedDate.toISOString().replace('Z', '').replace('T',' ').replace(/\.[\d]+/g,'');
//
//   return iso;
// };
function users(_, fileUpload, db, jwt) {
  var router = express.Router();

  /* GET users listing. */
  router.get('/', function (req, res, next) {
    res.send('respond with a resource');
  });
  router.post('/login', function (req, res, next) {
    let user = req.body;
    user.updated = new Date();
    let list = db.insert('users',user);
    let token = jwt.signObject(list[0]);
    res.header('token',token);
    res.status(200).send(JSON.stringify(list));
  });
  return router
}
module.exports = users;
